package com.wl.wuliu.controller;

import com.wl.wuliu.core.controller.BaseController;
import com.wl.wuliu.core.page.TableDataInfo;
import com.wl.wuliu.entity.Finance;
import com.wl.wuliu.entity.FinanceResult;
import com.wl.wuliu.entity.QueryEntity;
import com.wl.wuliu.result.AjaxResult;
import com.wl.wuliu.service.FinanceService;
import com.wl.wuliu.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * @Author: gutaozhen
 * @Date: 2024/5/15
 */
@RestController
@RequestMapping("/finance")
public class FinanceController extends BaseController {

    @Autowired
    private FinanceService financeService;

    /**
     * 列表查询
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo findList(QueryEntity queryEntity) {

        startPage();
        List<FinanceResult> list = financeService.findList(queryEntity);

        return getDataTable(list);
    }

    /**
     * 修改财务信息
     * @param finance
     * @return
     */
    @PostMapping("/update")
    public AjaxResult updateFinance(@RequestBody Finance finance) {

        return financeService.updateFinance(finance);
    }

    /**
     * 根据id查询财务信息
     * @param id
     * @return
     */
    @GetMapping("/getFinance")
    public AjaxResult getFinance(@RequestParam String id) {
        if (StringUtils.isEmpty(id)) {
            return AjaxResult.error("非法参数");
        }

        FinanceResult financeResult = financeService.getFinance(id);

        return AjaxResult.success(financeResult);
    }

    /**
     * 统计总利润
     * @return
     */
    @GetMapping("/statisticsTotalProfit")
    public AjaxResult statisticsTotalProfit(String startTime,String endTime,String dateType) {

        return AjaxResult.success(financeService.statisticsTotalProfit(startTime,endTime,dateType));
    }

    /**
     * 统计个人利润
     * @return
     */
    @GetMapping("/statisticsProfit")
    public AjaxResult statisticsProfit(String startTime,String endTime,String dateType,String userId) {

        return AjaxResult.success(financeService.statisticsProfit(startTime,endTime,dateType,userId));
    }

    /**
     * 导出运输车信息
     * @param response
     * @throws IOException
     */
    @GetMapping("/export")
    public void export(QueryEntity queryEntity,HttpServletResponse response) throws IOException {

        financeService.export(queryEntity,response);
    }

}
